#include "Comm.hpp"
#include "Fifo.hpp"

int main()
{
    // 1.获取key值
    key_t key = GetShmKeyOrDie();
    cout << "key:0x" << ToHex(key) << endl;

    // 2.获取共享内存
    int shmid = GetShm(key, defaultsize);
    cout << "shmid:" << shmid << endl;

    // 3.挂接共享内存
    char *addr = (char *)AttachShm(shmid);
    cout << "addr:" << ToHex((uint64_t)addr) << endl;

    memset(addr, 0, defaultsize);

    //5.通信
    Syns syn;
    syn.OpenWriteOrDie();
    
    for (char c = 'A'; c <= 'Z'; c++)
    {
        addr[c - 'A'] = c;
        sleep(1);
        syn.WakeUp();
    }

    // sleep(10);

    //4.去链接
    DetachShm(addr);
    std::cout << "Detach shm success, addr: " << ToHex((uint64_t)addr) << std::endl;
    // DebugShm(shmid);

    return 0;
}